#include "eigen/classification_accuracy.h"
#include "log.h"
namespace  ldl_eigen
{
double ClassificationAccuracy::accuracy(const Eigen::MatrixXf &predicts, const Eigen::MatrixXf &labels)
{
    double accuracy{};

    auto predicts_indices = row_max_indices(predicts);
    auto labels_indices = row_max_indices(labels);

    accuracy = (double)((predicts_indices.array() == labels_indices.array()).count()) / predicts_indices.size();
    return accuracy;
}

Eigen::VectorXi ClassificationAccuracy::row_max_indices(const Eigen::MatrixXf &matrix)
{
    Eigen::VectorXi indices(matrix.rows());
    for (int i = 0; i < matrix.rows(); ++i) {
        matrix.row(i).maxCoeff(&indices(i));
    }
    return indices;
}
}